package test.iso
{
	import flash.events.MouseEvent;
	import flash.geom.Point;
	
	import level4.engines.GameEngine;
	import level4.iso.DrawnIsoBox;
	import level4.iso.IsoUtil;
	import level4.iso.Point3D;

	public class IsoBoxTest extends IsoTest
	{
		private var lists:Array = [];
		public function IsoBoxTest()
		{
			super();
			addEventListener(MouseEvent.CLICK,onClick);
		}
		
		private function onClick(e:MouseEvent):void{
			var box:DrawnIsoBox = new DrawnIsoBox(20,Math.random()*0xffffff,20);

			var pos:Point3D = IsoUtil.ScreenToIso(new Point(e.stageX,e.stageY));
				pos.x = Math.round(pos.x/20) * 20;
				pos.y = Math.round(pos.y/20)*20;
				pos.z =Math.round(pos.z/20)*20;
			box.IsoPoint = pos;
			addChild(box);
			GameEngine.addComponent(box);
			
			lists.push(box);
			sort();
		}
		//按depth进行排序,然后重新添加
		private function sort():void{
			lists.sortOn("depth",Array.NUMERIC);
			for(var i:int = 0;i<lists.length;i++){
				addChild(lists[i]);
			}
		}
	}
}